home *** CD-ROM | disk | FTP | other *** search
Wrap
<%@ LANGUAGE="JSCRIPT" %> <%Response.Buffer = true%> <HTML> <HEAD> <TITLE>MSDBUpdate Form Handler</TITLE> <META NAME="Author" CONTENT="Application Methods Inc."> </HEAD> <BODY> <br> <!--#INCLUDE FILE="MSGlobal.inc"--> <!--#INCLUDE FILE="MSDBConnection.inc"--> <!--#INCLUDE FILE="MSDBUpdate.inc"--> <% write("<h3>Error Output:</h3>"); write("<p>If you are seeing this page, an ASP or database server processing error has occurred. Please report the errors on this page to your server or database administrator.<P>"); //////////////////////////////////////////////////////////////////// // // // Fusion ASP Components // // Custom Form Handler: MSDBUpdateHandler // // // //////////////////////////////////////////////////////////////////// /* Object: MSDBUpdateHandler Version: 1.0 9/24/97 Written By: Application Methods, Inc. 6300 Southcenter Blvd. Seattle, WA 98188 (206) 244-2400 http://www.appmethods.com Technical Overview: Construct DatabaseConnection object Construct UpdateTable object Check for expected DatabaseConnection property existances and populate object; type user password server database if all exists call connect() Check for expected UpdateTable property existances and populate object; action tableName primaryKeyFieldCount primaryKeyFieldNames primaryKeyFieldValues Extract field info: field count fieldNames fieldValues if all exist, construct object and call execute(); =====================================================================*/ // Variables var pre = "amaspHidden_"; // Prefix on all hidden fields var preName = "amaspComponent_"; // Prefix on submiting button name, for name identification var clientPre = "NETSCAPE_ASP"; // Client & Server URL Client object maintenance prefix var dbObjName ; // Hard coded name at this point var dbDatabaseType = ""; var dbODBCDatabaseType = ""; var dbDatabaseServer = ""; var dbUserName = ""; var dbPassword = ""; var dbGlobalConn = ""; // Create new, clean request object write("\r\n<BR>Creating new, clean request object..."); var myRequest = new NewRequest(); // Debugging function //======================================================================== viewObject(myRequest.newRequest,"Request"); // Construct objects write("\r\n<BR>Creating new database objects..."); // Preserve old globalConn flag in case it is using the initial page since // we don't want to write over it. var oldProjInitPage = Application("globalConn"); upd1 = new MSDBUpdate(); dbObjName = upd1.dataSource; // Hard coded name at this point Application("globalConn") = oldProjInitPage; // Get database component properties if (Application("globalConn")!="true") { // Get database properties from Request Object dbDatabaseType = myRequest.newRequest[pre+dbObjName+"_databaseType"]; dbODBCDatabaseType = myRequest.newRequest[pre+dbObjName+"_ODBCDatabaseType"]; dbDatabaseServer = myRequest.newRequest[pre+dbObjName+"_databaseServer"]; dbUserName = myRequest.newRequest[pre+dbObjName+"_userName"]; dbPassword = myRequest.newRequest[pre+dbObjName+"_password"]; dbGlobalConn = myRequest.newRequest[pre+dbObjName+"_globalConn"]; // Create database object // Must pass all properties in constructor because of values used // in function in the constructor eval(dbObjName + " = new MSDBConnection(\""+dbObjName+"\",\"" +dbDatabaseType+"\",\"" +dbODBCDatabaseType+"\",\"" +dbDatabaseServer+"\",\"" +dbUserName+"\",\"" +dbPassword+"\",\"" +dbGlobalConn+"\")"); } // Get Update component properties // Get button name for (prop in myRequest.newRequest) { if (prop.indexOf(preName) == 0) { var no = preName.length; var pno = prop.length; if ((prop.substring(pno-2,pno).toUpperCase() == ".X") || (prop.substring(pno-2,pno).toUpperCase() == ".Y")) { pno = pno-2; } upd1.name = prop.substring(no,pno); } } // Proceed only if name found if (upd1.name != "") { var updateButtonName = upd1.name; // Get Update properties upd1.tableName = myRequest.newRequest[pre+updateButtonName+"_tableName"] upd1.action = myRequest.newRequest[pre+updateButtonName+"_action"] upd1.primaryKeyFieldCount = myRequest.newRequest[pre+updateButtonName+"_primaryKeyFieldCount"] upd1.errorURL = myRequest.newRequest[pre+updateButtonName+"_errorURL"] upd1.successURL = myRequest.newRequest[pre+updateButtonName+"_successURL"] // Proceed only if counts found if (upd1.action != "modify" || upd1.action != "delete" || (upd1.action != "add" && upd1.primaryKeyFieldCount+"" != "")) { // Get primary key field names and values upd1primaryKeyFieldNames = new Array(); upd1primaryKeyFieldValues = new Array(); upd1primaryKeyFieldDataTypes = new Array(); for (var fcnt=0; fcnt < parseInt(upd1.primaryKeyFieldCount,10); fcnt++) { upd1primaryKeyFieldNames[fcnt] = "|"; upd1primaryKeyFieldValues[fcnt] = "|"; upd1primaryKeyFieldDataTypes[fcnt] = "|"; } //debug("Getting primary key field names and values...") write("\r\n<BR>Getting primary key field names and values...") for (prop in myRequest.newRequest) { for (var fcnt=0; fcnt < parseInt(upd1.primaryKeyFieldCount,10); fcnt++) { if (prop == pre+updateButtonName+"_primaryKeyFieldNames"+fcnt) { upd1primaryKeyFieldNames[fcnt] = myRequest.newRequest[prop]; } if (prop == pre+updateButtonName+"_primaryKeyFieldValues"+fcnt) { upd1primaryKeyFieldValues[fcnt] = myRequest.newRequest[prop]; } if (prop == pre+updateButtonName+"_primaryKeyFieldDataTypes"+fcnt) { upd1primaryKeyFieldDataTypes[fcnt] = myRequest.newRequest[prop]; } } // end inner for loop } // end outer for loop // Proceed only if all expected primary key field names and values found ?? (Later) // if all systems go so far then continue else quit // Get field names and values upd1fieldNames = new Array(); upd1fieldValues = new Array(); upd1fieldDataTypes = new Array(); var upd1fieldCount=0; //debug("Getting field names and values..."); write("\r\n<BR>Getting field names and values..."); for ( prop in myRequest.newRequest) { // Ignore properties with the prefixes defined in pre, preName and clientPre if (prop.indexOf(pre) == -1 && prop.indexOf(preName) == -1 && prop.indexOf(clientPre) == -1) { upd1fieldNames[upd1fieldCount] = prop; upd1fieldValues[upd1fieldCount] = myRequest.newRequest[prop]; upd1fieldDataTypes[upd1fieldCount] = myRequest.newRequest[pre+prop+"_dataType"]; upd1fieldCount++; } // end if upd1.fieldCount=upd1fieldCount } // end outer for loop // Final assembly upd1.primaryKeyFieldNames = upd1primaryKeyFieldNames; upd1.primaryKeyFieldValues = upd1primaryKeyFieldValues; upd1.primaryKeyFieldDataTypes = upd1primaryKeyFieldDataTypes; upd1.fieldNames = upd1fieldNames; upd1.fieldValues = upd1fieldValues; upd1.fieldDataTypes = upd1fieldDataTypes; // Tell update object about the database properties so it can use them to make // determinations about data types in the SQL statement based on the type of database. upd1.ODBCDatabaseType = (Application("globalConn")=="true") ? Session("ODBCDatabaseType") : eval(dbObjName + ".ODBCDatabaseType"); upd1.databaseType = (Application("globalConn")=="true") ? Session("databaseType") : eval(dbObjName + ".databaseType"); // Debugging functions ========================================================================= // Emit database properties write("\r\n<BR><HR>Outputting database properties..."); if (Application("globalConn")!="true") eval(dbObjName + ".emitProperties()"); else write("Using Global Database"); // Emit updateTable properties write("\r\n<BR><HR>Outputting MSDBUpdate properties..."); upd1.emitProperties(); write("\r\n<BR><HR>Outputting SQL builds..."); write("\r\n<BR>"+upd1.buildWhereSQL()); write("\r\n<BR>"+upd1.buildAddSQL()); write("\r\n<BR>"+upd1.buildModifySQL()); write("\r\n<BR>"+upd1.buildDeleteSQL()); upd1.execute(); } // End key field count not found else { write("\r\n<BR>Required primary key field count not found in hidden fields"); debug("Required primary key field count not found in hidden fields"); Response.Clear(); Response.Redirect (upd1.errorURL); Response.End(); } } // End name not found else { write("\r\n<BR>Submit button name not found in hidden fields"); debug("Submit button name not found in hidden fields"); Response.Clear(); Response.Redirect (upd1.errorURL); Response.End(); } %> </BODY> </HTML>